<?php

/*
	info: 后台管理函数库
	date: 2011-11-23
*/

if (!defined('ADMIN_WEBINROOT'))
{
	header("HTTP/1.0 404 Not Found");
	exit();
}

if (defined('ADMIN_FUNC'))
{
	return;
}
define('ADMIN_FUNC', TRUE);

//添加管理日志
function admin_AddLog($strlog)
{
	global $db, $webconfig, $user, $webserver;
	$db->Query("INSERT INTO {$webconfig['dbpre']}log(admin_user_id,admin_username,log,time,ip) VALUES('{$user['adminuid']}','{$user['adminusername']}','$strlog','{$webserver['timestamp']}','{$user['ip']}')");
}

//检测是否来自表单提交
function admin_CheckFromForm($strgourl = '')
{
	global $webcookie;
	if (isset($webcookie['fromform']) && $webcookie['fromform']=='ok')
	{
		global_ClearCookie('fromform');
		return TRUE;
	}
	else
	{
		if ($strgourl!='')
		{
			global_GoToUrl($strgourl);
		}
		return FALSE;
	}
}

//加密管理密码
function admin_EncodePassword($strpass)
{
	return ($strpass!='') ? md5('vip'.md5($strpass).'247') : '';
}

//执行SQL语句
function admin_RunQuery($sql)
{
	global $db;
	$sql = str_replace("\r", "\n", $sql);
	$sql = preg_replace("/(^|\n)(\-{2}|#)(.*)/", "\n", $sql);
	$ret = explode(";\n", $sql);
	foreach ($ret as $query)
	{
		$query = trim($query);
		if ($query != '')
		{
			$db->Query($query);
		}
	}
}

//标记表单提交
function admin_StartFromForm()
{
	global_SetCookie('fromform', 'ok');
}

//提示信息
function admin_ShowMessage($showmessage, $urlforward = '', $extra = '')
{
	global $db, $user, $webcache, $webglobal, $webserver, $webcookie, $webrequest, $webconfig;
	$webglobal['showmessage'] = $showmessage;
	$webglobal['smgurlforward'] = $urlforward;
	$webglobal['smgextra'] = $extra;
	$webglobal['isautojump'] = FALSE;
	$webglobal['adminremurl'] = FALSE;
	if ($webglobal['smgurlforward']!='' && $webglobal['smgextra']!='STOP')
	{
		$webglobal['isautojump'] = TRUE;
		$webglobal['htmlhead'][] = '<meta http-equiv="refresh" content="3;url='.$webglobal['smgurlforward'].'" />';
	}
	template_Display('showmessage', 1);
	exit();
}

?>